import { Body, Controller, Delete, HttpCode, HttpStatus, Param, ParseIntPipe, Patch, Post, UseGuards } from '@nestjs/common';
import { ApiCreatedResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { CategoryService } from 'src/service/category/category.service';
import { CategoryDto } from './dto/category.dto';
import { CategoryReqDto } from './dto/category.req.dto';
import { AuthGuard } from '@nestjs/passport';
@ApiTags('后台管理系统-角色管理')
@Controller('category')
export class CategoryController {
    constructor(private categoryService: CategoryService){}

    @ApiOperation({
        summary:'类目新增',
        description:'类目新增'
    })
    @ApiCreatedResponse({
        status:200,
        description:'成功时返回的数据'
    })
    @Post('add')
    @UseGuards(AuthGuard('jwt'))
    @HttpCode(HttpStatus.OK)
    async categoryAdd(@Body() categoryDto: CategoryDto){
        const message = await this.categoryService.add(categoryDto)
        return message
    }

    @ApiOperation({
        summary:'类目删除',
        description:'类目删除'
    })
    @ApiCreatedResponse({
        status:200,
        description:'成功时返回的数据'
    })
    @Delete('/:id')
    @UseGuards(AuthGuard('jwt'))
    @HttpCode(HttpStatus.OK)
    async categoryDelete(@Param('id',new ParseIntPipe())id: number) {
        return await this.categoryService.destoryCategoryById(id)
    }

    @ApiOperation({
        summary:'类目修改',
        description:'类目修改'
    })
    @ApiCreatedResponse({
        status:200,
        description:'成功时返回的数据'
    })
    @Patch('/:id')
    @UseGuards(AuthGuard('jwt'))
    @HttpCode(HttpStatus.OK)
    async categoryUpdate(@Param('id',new ParseIntPipe())id: number,@Body() body: CategoryDto) {
        return await this.categoryService.modifyCategoryById(id,body)
    }

    // 查找所有
    @ApiOperation({
        summary:'类目查找分页',
        description:'类目查找分页'
    })
    @ApiCreatedResponse({
        status:200,
        description:'成功时返回的数据'
    })
    @Post('find')
    @HttpCode(HttpStatus.OK)
    async categoryFind(@Body() body: CategoryReqDto) {
        return await this.categoryService.categoryListPage(body)
    }

    // 查找所有
    @ApiOperation({
        summary:'类目查找不分页',
        description:'类目查找不分页'
    })
    @ApiCreatedResponse({
        status:200,
        description:'成功时返回的数据'
    })
    @Post('findAll')
    @HttpCode(HttpStatus.OK)
    async categoryFindAll() {
        return await this.categoryService.categoryList()
    }

}
